<!--
 * @Author: ningjz
 * @Date: 2022-04-11 18:05:46
 * @Description: CPI与酒店月均价放大modal
-->
<template>
  <div class="right-top">
    <com-box :title="BarState.title" class="com-box-title">
      <!-- <template #titleLeft>
        <div class="header-left header-box">{{ BarState.unit }}</div>
      </template> -->
      <template v-slot>
        <div class="nav">
          <div class="nav-warnLine"></div>
          <div class="box-bar echart-item">
            <charts :params="BarState.params"></charts>
          </div>
        </div>
      </template>
    </com-box>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive } from 'vue'
import comBox from '@/components/comBox/comBox.vue'
import httpRequest from '@/service'

export default defineComponent({
  name: 'rightTopModal',
  components: {
    comBox
  },
  setup() {
    //折线图
    const BarState: any = reactive({
      title: '',
      isGroup: false,
      unit: '',
      params: {
        height: '600px',
        loading: true,
        forceRedraw: true, // 强制重绘
        map: {},
        options: {
          dataset: {
            dimensions: [],
            source: []
          },
          legend: {
            show: true,
            right: 0,
            top: 3,
            itemWidth: 15 * 1.9,
            width: '70%',
            itemStyle: {
              decal: {
                symbol: ''
              }
            },
            textStyle: {
              fontSize: 14 * 1.9 + 'px'
            }
          },
          xAxis: [
            {
              axisLabel: {
                fontSize: 14 * 1.9 + 'px'
              }
            }
          ],
          yAxis: [
            {
              min: '60',
              splitLine: {
                show: false
              },
              name: [''],
              axisLabel: {
                fontSize: 14 * 1.9 + 'px'
              }
            }
          ],
          grid: {
            top: 30 * 1.9,
            bottom: 49 * 1.9,
            left: 0,
            right: 0
          },
          dataZoom: [
            {
              show: true,
              type: 'slider',
              start: 0,
              end: 100,
              width: '96%',
              left: '3%',
              bottom: 22 * 1.9,
              height: 15 * 1.9,
              borderColor: '#166beb',
              handleStyle: {
                color: '#166beb',
                borderColor: '#166beb',
                borderWidth: 4
              },
              moveHandleSize: 10 * 1.9,
              moveHandleStyle: {
                color: '#166beb'
              },
              textStyle: {
                color: '#00c6ff',
                fontSize: 14 * 1.9 + 'px'
              },
              emphasis: {
                handleStyle: {
                  color: '#00c6ff',
                  borderColor: '#00c6ff',
                  borderWidth: 4
                },
                moveHandleStyle: {
                  color: '#00c6ff'
                }
              }
            }
          ],
          series: [
            {
              type: ['line', 'line', 'line', 'line', 'line', 'line'],
              connectNulls: true,
              label: {
                show: false
              },
              itemStyle: {
                color: ['#00AFFB', '#FAA51D', '#1da7ff', '#ec6941', '#ffba0a']
              },
              areaStyle: {
                opacity: 0
              }
            },
            {
              data: [9800],
              type: 'pictorialBar', // 顶部
              barMaxWidth: '62',
              symbolPosition: 'end',
              symbolOffset: [34, '-100%'],
              symbolSize: [62 * 1.9, 2 * 1.9],
              symbol: 'rect',
              color: '#fff', // Specify the color using rgb format
              zlevel: 2
            }
          ]
        }
      },
      getData: () => {
        BarState.params.loading = true
        httpRequest
          .get({ url: 'M2P3CpiLine', params: {} })
          .then((res) => {
            if (res.code === 200 && Object.keys(res.map).length > 0) {
              BarState.params.options.dataset.dimensions = [
                'name',
                ...Object.keys(res.map)
              ]
              BarState.params.options.dataset.source = res.data
              BarState.unit = res.unit ? `单位：${res.unit}` : ''
              BarState.title = res.title
              BarState.params.map = res.map
              BarState.params.loading = false
            }
          })
          .catch(() => {
            console.log('请求失败')
          })
      }
    })

    BarState.getData()

    return {
      BarState
    }
  }
})
</script>

<style lang="less" scoped>
@MX: 1.9; // 放大倍数

.right-top {
  width: 620px * @MX;
  height: 370px * @MX;
  overflow: hidden;

  .com-box-title {
    ::v-deep(.com-header) {
      height: 45px * @MX;
    }
    ::v-deep(.title) {
      font-size: 20px * @MX;
      line-height: 45px * @MX;
      background-size: 264px * @MX 45px * @MX;
      flex: 0 0 264px * @MX;
    }
  }

  .nav {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    padding-left: 5px * @MX;
    .echart-item {
      width: 100%;
    }
    .box-bar {
      height: 100%;
      padding: 7px * @MX 30px * @MX 7px * @MX 15px * @MX;
    }
  }
}
.header-box {
  white-space: nowrap;
  width: 100%;
  height: 100%;
  font-size: 14px * @MX;
  text-align: left;
  color: #46ede8;
  font-family: 'Microsoft YaHei';
  display: flex;
  align-items: flex-end;
  font-weight: bold;
}

.header-left {
  justify-content: flex-start;
  padding: 0px 20px * @MX;
}
</style>
